package com.ccjq.jq173.shosestore.member.service.impl;

import com.ccjq.jq173.shosestore.core.util.Md5Utils;
import com.ccjq.jq173.shosestore.core.util.UuidUtils;
import com.ccjq.jq173.shosestore.member.dao.UserDao;
import com.ccjq.jq173.shosestore.member.dao.impl.UserDaoImpl;
import com.ccjq.jq173.shosestore.member.po.User;
import com.ccjq.jq173.shosestore.member.service.UserService;

public class UserServiceImpl implements UserService {
    private UserDao userDao;
    public UserServiceImpl()
    {
        userDao=new UserDaoImpl();
    }
    @Override
    public int regist(String username, String password, String mobilePhone)
    {
        String userId= UuidUtils.generateShotUUID("U",10);
        password= Md5Utils.EncoderByMd5(password);
        return userDao.save(userId,username,password,mobilePhone);
    }

    @Override
    public int isExists(String username) {
        User user=userDao.findUserByUserName(username);
        return user==null?0:1;
    }

    @Override
    public User login(String username, String password) {
        password=Md5Utils.EncoderByMd5(password);
        User user= userDao.findUserByNmaePassword(username,password);
        return user;
    }

    @Override
    public User loadUser(String username) {
        User user=userDao.findUserByUserName(username);
        return user;
    }

    @Override
    public User loadUserById(String userId) {
        User user=userDao.findUserByUserId(userId);
        return user;
    }
}
